<template>
  <view class="partOrderCard">
    <view class="header">
      <view class="date">{{ dateStringFilter }}</view>
    </view>
    <view class="content">
      <view class="content_item">
        <view class="label">{{ item.checkName + ":" }}</view>
        <view class="desc" v-if="item.typeStatus !== 2">{{
          item.workName
        }}</view>
        <view class="desc" v-if="item.typeStatus == 2 &&
            item.problemItemNames &&
            item.problemItemNames.length
            ">
          <text v-for="(e, i) in item.problemItemNames" :key="i">{{ e }}
            <text>,</text>
          </text>
          <text>{{ item.workName }}</text>
        </view>
        <view class="desc" v-if="item.partsNames">
          <text>{{ sliceStr(item.partsNames) }}</text>
        </view>
      </view>
      <!-- 保养 -->
      <view class="content_item" v-if="item.typeStatus == 1">
        <view class="label">保养结果:</view>
        <view class="desc" v-if="item.result != null" :style="{ color: item.result == 1 ? '#6BC013' : '#E02020' }">
          {{ item.result == 1 ? "正常" : "异常" }}
        </view>
        <view v-else>
          <view v-for="(i, k) in item.recordData.options" :key="k">
            <text v-if="i.default" :style="{ color: i.result == 1 ? '#6BC013' : '#E02020' }">
              {{ i.name }}
            </text>
          </view>
        </view>
      </view>
      <view v-if="item.recordDataValues && item.recordDataValues.length">
        <view class="recordBox" v-for="(e, index) in item.recordDataValues" :key="index">
          <view :class="['record_item', index == item.recordDataValues.length - 1 ? 'noBorder' : '']">
            <view class="label">{{
              item.recordDataValues.length == 1 ? "记录" : "记录" + (index + 1)
            }}:</view>
            <view class="record_content">
              <view class="desc"></view>
              <view class="remark">{{ e.remarks.val }}</view>
              <view class="imgBox" v-if="e.files.val && e.files.val.length">
                <image v-for="(img, j) in e.files.val" :src="img.type == 'image' ? img.url : '/static/images/video.png'"
                  mode="" @click="preViewFile(e.files.val, j)" :key="j" />
              </view>
            </view>

          </view>

        </view>
      </view>
      <!-- 维修记录 -->
      <view v-if="item.typeStatus == 2 || item.typeStatus == 4">
        <view class="content_item">
          <view class="label">维修记录:</view>
          <view class="desc">{{ item.disposeDesc }}</view>
        </view>
        <view class="imgBox" v-if="item.disposeImgUrl && item.disposeImgUrl.length">
          <image v-for="(img, j) in item.disposeImgUrl" :src="img.type == 'image' ? img.url : '/static/images/video.png'"
            mode="" @click="preViewFile(item.disposeImgUrl, j)" :key="j" />
        </view>
      </view>
    </view>

    <!-- 如果是保养 -->
    <!-- <view class="right">
          <view
            class="desc"
            v-if="item.result !== null"
            :style="{ color: statusMap[item.result].color }"
            >{{ statusMap[item.result].text }}</view
          >
          <view class="desc">{{ item.disposeDesc }}</view>
          <view class="imgBox">
            <image
              src="@/static/images/default.png"
              mode=""
              v-for="(item, index) in 8"
              :key="index"
            />
          </view>
        </view> -->
  </view>
</template>

<script>
export default {
	props: {
		item: {
			type: Object,
		},
	},
	computed: {
		dateStringFilter() {
			if (!this.item) {
				return '';
			} else {
				return this.item.createTime.replaceAll('-', '/');
			}
		},
	},

	data() {
		return {
			statusMap: {
				1: {
					text: '正常',
					color: '#6BC013',
				},
				2: {
					text: '异常',
					color: '#E02020',
				},
				3: {
					text: '无此项',
					color: '#F7B500',
				},
			},
		};
	},
	methods: {
		sliceStr(str) {
			if (str.length >= 15) {
				str = str.slice(0, 15) + '...';
			}
			return str;
		},
		preViewFile(list, index) {
      this.$previewMedia({
				sources: list,
				current: index,
			});
		},
	},
};
</script>

<style lang="scss" scoped>
.partOrderCard {
  background: #fff;
  border-radius: 8rpx;
  margin-bottom: 16rpx;

  .header {
    border-bottom: 2rpx solid #eeeeee;

    .date {
      height: 68rpx;
      padding: 0 20rpx;
      display: flex;
      align-items: center;
      color: #999999;
      font-size: 24rpx;
    }
  }

  .content {
    padding: 26rpx 20rpx;
    font-size: 26rpx;
    color: #666;

    .content_item {
      display: flex;
      margin-bottom: 16rpx;

      .label {
        margin-right: 26rpx;
        min-width: 112rpx;
      }

      .desc {
        display: flex;
        flex: 1;
        flex-wrap: wrap;
      }
    }

    .imgBox {
      display: flex;
      flex-wrap: wrap;

      image {
        width: 96rpx;
        height: 96rpx;
        margin-right: 22rpx;
        margin-top: 16rpx;
      }
    }
  }

  .record_item {
    display: flex;
    border-bottom: 2rpx solid #eeeeee;
    ;
    padding: 16rpx 0;

    .label {
      margin-right: 26rpx;
      width: 112rpx;
    }

    .record_content {
      display: flex;
      flex: 1;
      flex-direction: column;
    }
  }

  .noBorder {
    border: none !important
  }
}
</style>
